package com.gxa.controller.investment;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.Result;
import com.gxa.entity.investment.InvestmentPlan;
import com.gxa.entity.investment.Plan;
import com.gxa.entity.investment.PlanAuthorization;
import com.gxa.service.investment.PlanAuthorizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * <p>
 * 招商配置——项目授权 前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-15 10:58:56
 */
@Api(tags = "招商配置/项目授权")
@RestController
@RequestMapping("/plan/authorization")
public class PlanAuthorizationController {
    @Autowired
    private PlanAuthorizationService planAuthorizationService;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("按条件查询")
    @GetMapping("/query")
    public Result query(String authorizationPut,Integer pageNum, Integer pageSize){
        try {
            Map<String,Object> result = planAuthorizationService.queryByAuthorizationPut(authorizationPut, pageNum, pageSize);

            return Result.success(result);
        }catch (Exception e){
            e.printStackTrace();
            return Result.failed("query failed");
        }

    }


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("添加授权")
    @PostMapping("/add")
    public Result add(@RequestBody PlanAuthorization planAuthorization){
        int results = planAuthorizationService.add(planAuthorization);
        if (results == 1){
            return Result.success("add success");
        }else {
            return Result.failed("add failed");
        }
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除授权")
    @DeleteMapping("/del/{id}")
    public Result delete(@PathVariable("id") Integer id){
        int results = planAuthorizationService.delete(id);
        if (results == 1){
            return Result.success("del success");
        }else {
            return Result.failed("del failed");
        }
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑授权")
    @PutMapping("/update")
    public Result update(@RequestBody PlanAuthorization planAuthorization){
        int results = planAuthorizationService.update(planAuthorization);
        if (results == 1){
            return Result.success("update success");
        }else {
            return Result.failed("update failed");
        }
    }


}
